package com.bdqn.t330.ch10;

import com.bdqn.t330.ch10.dao.SysUserMapper;
import com.bdqn.t330.ch10.entity.SysUser;
import com.bdqn.t330.ch10.service.UserService;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.List;

public class UserTester {

    @Test
    public void loginTest() {
        //初始化spring容器
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        String[] beanDefinitionNames = context.getBeanDefinitionNames();
        for (String beanDefinitionName : beanDefinitionNames) {
            System.out.println(beanDefinitionName);
        }
        SysUserMapper sysUserMapper = (SysUserMapper) context.getBean("sysUserMapper");
        SysUser sysUser = new SysUser();
        sysUser.setUserCode("admin");
        sysUser.setUserPassword("1");
        int count = sysUserMapper.login(sysUser);
        System.out.println(count);
    }

    @Test
    public void loginBizTest() {
        //初始化spring容器
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        String[] beanDefinitionNames = context.getBeanDefinitionNames();
        for (String beanDefinitionName : beanDefinitionNames) {
            System.out.println(beanDefinitionName);
        }
        UserService userService = (UserService) context.getBean("userService");
        SysUser sysUser = new SysUser();
        sysUser.setUserCode("admin");
        sysUser.setUserPassword("1");
        int count = userService.loginBiz(sysUser);
        System.out.println(count);
    }

    @Test
    public void getListPageTest() {
        //初始化spring容器
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        String[] beanDefinitionNames = context.getBeanDefinitionNames();
        SysUserMapper sysUserMapper = (SysUserMapper) context.getBean("sysUserMapper");
        // List<SysUser> list = sysUserMapper.getUserListPage(0, 5);
        // for (SysUser sysUser : list) {
        //     System.out.println(sysUser);
        // }
    }
}
